/*
  EOMono
  Copyright 2007, Adam Tauno Williams (Whitemice Consulting)
  License: LGPLv2  < http://www.gnu.org/licenses/lgpl-2.1.html >
 */
using System;
using System.Collections;
using System.Collections.Generic;
using Whitemice.EOMono;

namespace Whitemice.DbTest
{
  class MainClass
  {
    private const string dsn  = "Server=localhost;Database=OGo;User Id=OGo";
    
    public static void Main(string[] args)
    {
      IList<IEORecord> results;
      IEORecord        record;
        
      EOModel.Load("ZideNET.model.xml");
      
      IEOConnection connection = new EOPGConnection(dsn);
      
      results = connection.Run("Person:SQLFetch", 
                               "qualifier", "company_id = 10100",
                               "limit", 10);
      foreach(IEORecord r in results)
      {
        Console.WriteLine("{0} {1} {2}", r["objectId"].Value, r["name"].Value, r["owner_id"].Value);
        r["name"].Value = "Fred";
        r.Save();
        Console.WriteLine("{0} {1} {2}", r["objectId"].Value, r["name"].Value, r["owner_id"].Value);
        r["name"].Value = "Adam";
        r.Save();
        Console.WriteLine("{0} {1} {2}", r["objectId"].Value, r["name"].Value, r["owner_id"].Value);
      }
      
      results = connection.Run("Person:SQLFetch", 
                               "criteria", new object[] { "objectId", 10100 },
                               "limit", 10);
      foreach(IEORecord r in results)
      {
        Console.WriteLine("{0} {1} {2}", r["objectId"].Value, r["name"].Value, r["owner_id"].Value);
      }
    }
  }
}
